package com.czk.protocol.http;

import com.czk.framework.Invocation;
import com.czk.framework.Protocol;
import com.czk.framework.URL;

import java.io.IOException;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/4/15 15:42
 */
public class HttpProtocol implements Protocol {
    private HttpClient httpClient;

    @Override
    public void start(URL url) {
        new HttpServer().start(url.getHostname(), url.getPort());
    }

    @Override
    public String send(URL url, Invocation invocation) {
        try {
            if (httpClient == null) {
                httpClient = new HttpClient();
            }
            return httpClient.send(url.getHostname(), url.getPort(), invocation);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
